<template >
  <fragment>
    <template v-for="(item, index) in list" >
      <el-submenu :index="item.label" v-if="item.children && item.children.length > 0" :key="index">
        <template slot="title">
          <i :class="'el-icon-' + item.icon"></i>
          <span>{{ item.label }}</span>
        </template>
        <menu-list :list="item.children"/>
      </el-submenu>

      <el-menu-item :index="item.routerPath" :key="item.routerPath" @click="clickMenu(item)" v-else>
          <i :class="'el-icon-' + item.icon"></i>
          <span>{{ item.label }}</span>
      </el-menu-item>

    </template>
  </fragment>
</template>

<script>
export default {
  name:'MenuList',
  props: {
    list: Array
  },
  methods:{
    clickMenu(item) {
      if (this.$route.name !== item.name) {
        this.$router.push({ name: item.name })
        this.$store.commit('selectMenu', item)
      }
    }
  }
}
</script>
